home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d18
/
nrpas13.arc
/
POLCOF.DEM
< prev
next >
Wrap
Text File
|
1991-05-01
|
2KB
|
66 lines
PROGRAM d3r8 (input,output);
(* driver for routine POLCOF *)
LABEL 1;
CONST
np=5;
pi=3.1415926;
TYPE
glnarray = ARRAY [1..np] OF real;
VAR
i,j,nfunc : integer;
f,sum,x : real;
coeff,xa,ya : glnarray;
(*$I MODFILE.PAS *)
(*$I POLINT.PAS *)
(*$I POLCOF.PAS *)
BEGIN
FOR nfunc := 1 to 2 DO BEGIN
IF (nfunc = 1) THEN BEGIN
writeln;
writeln ('sine function from 0 to pi');
FOR i := 1 to np DO BEGIN
xa[i] := i*pi/np;
ya[i] := sin(xa[i])
END
END ELSE IF (nfunc = 2) THEN BEGIN
writeln;
writeln ('exponential function from 0 to 1');
FOR i := 1 to np DO BEGIN
xa[i] := 1.0*i/np;
ya[i] := exp(xa[i])
END
END ELSE BEGIN
GOTO 1
END;
polcof(xa,ya,np,coeff);
writeln;
writeln (' coefficients');
FOR i := 1 to np DO BEGIN
writeln (coeff[i]:12:6)
END;
writeln;
writeln ('x':9,'f(x)':13,'polynomial':15);
FOR i := 1 to 10 DO BEGIN
IF (nfunc = 1) THEN BEGIN
x := (-0.05+i/10.0)*pi;
f := sin(x)
END ELSE IF (nfunc = 2) THEN BEGIN
x := -0.05+i/10.0;
f := exp(x)
END;
sum := coeff[np];
FOR j := np-1 DOWNTO 1 DO BEGIN
sum := coeff[j]+sum*x
END;
writeln (x:12:6,f:12:6,sum:12:6)
END;
writeln ('************************************');
writeln ('press RETURN');
readln
END;
1:
END.